package com.atguigu03.threadsafe.runnablesafe;

/**
 * ClassName: Windows1
 * Package: com.atguigu03.threadsafe.runnablesafe
 * Description:
 *
 * @Author BuTang
 * @Create 2023/5/15 10:13
 * @Version 1.0
 */
public class Windows1 {
    public static void main(String[] args) {
        Windows2 a = new Windows2();

        Thread b = new Thread(a);
        Thread c = new Thread(a);
        Thread d = new Thread(a);

        b.setName("窗口一");
        c.setName("窗口二");
        d.setName("窗口三");

        b.start();
        c.start();
        d.start();
    }
}

class Windows2 implements Runnable {
    static int ticket = 100;
    boolean isFlag = true;
    @Override
    public void run() {
        while (ticket >0){
            show();
        }

    }

    public synchronized void show() {

        if (ticket > 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "-" + "售票成功：" + ticket);
            ticket--;
        }


    }
}